package logic

import (
	"context"
	"home-manage/homerpc/homerpc"

	"home-manage/api/internal/svc"
	"home-manage/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HoseListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHoseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HoseListLogic {
	return &HoseListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HoseListLogic) HoseList(req *types.HouseListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.HomeRpc.HouseList(l.ctx, &homerpc.HoseListRequest{
		Page:          req.Page,
		Size:          req.Size,
		PriceOrder:    req.PriceOrder,
		CreateAtOrder: req.CreateAtOrder,
		StartMi:       req.StartMi,
		EndMi:         req.EndMi,
		Address:       req.Address,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}
	return &types.Response{
		Message: "查询成功",
		Data:    list,
		Code:    200,
	}, nil
}
